package com.ruoyi.resource.service.impl;


import com.ruoyi.resource.service.IFileOperator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class FIleOperatorImpl implements IFileOperator {


    @Value("${video.root}")
    private String videoFolder;

    @Value("${theme.root}")
    private String themeFolder;

    @Value(("${screenSave.root}"))
    private String screenSaveFolder;


    @Override
    public boolean DeleteFileByScreenId(Integer screenId) {
        String pdfPath = videoFolder + '/' + screenId + ".pdf";
        String jpgPath = videoFolder + '/' + screenId + ".jpg";
        String pngPath = videoFolder + '/' + screenId + ".png";
        String videoPath = videoFolder + '/' + screenId + ".mp4";
        return   new File(pdfPath).delete() || new File(jpgPath).delete() || new File(pngPath).delete() || new File(videoPath).delete();

    }

    @Override
    public boolean DeleteThemeByScreenId(Integer screenId) {
        String pdfPath = themeFolder + '/' + screenId + ".pdf";
        String jpgPath = themeFolder + '/' + screenId + ".jpg";
        String pngPath = themeFolder + '/' + screenId + ".png";
        String videoPath = themeFolder + '/' + screenId + ".mp4";
        return   new File(pdfPath).delete() || new File(jpgPath).delete() || new File(pngPath).delete() || new File(videoPath).delete();

    }

    @Override
    public boolean DeleteScreenSaveByBrowserId(Integer browserId) {
        String jpgPath = screenSaveFolder + '/' + browserId + ".jpg";
        String pngPath = screenSaveFolder + '/' + browserId + ".png";
        Boolean jpgFlag = new File(jpgPath).delete();
        Boolean pngFlag = new File(pngPath).delete();
        return jpgFlag||pngFlag;

    }
}
